import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [
  {
    // 一级路由
    path: '/',
    redirect: '/login',
    component: () => import('@/views/home/index.vue'),
    // 二级路由
    children: [
    // 主页路由
      {
        path: 'home',
        name: 'home',
        title: '首页',
        component: () => import('@/views/layout/index.vue')
      },
      // 房产详情页路由
      {
        path: 'houseDetail/:id',
        name: 'houseDetail',
        title: '房产详情页',
        component: () => import('@/views/houseDetail/index.vue'),
        props: (route) => ({ houseId: route.params.id })
      },
      // 房产分类
      {
        path: 'houseClassify',
        name: 'houseClassify',
        title: '房产分类',
        component: () => import('@/views/houseClassify/index.vue')
      },
      // 房产分类列表
      {
        path: 'houseClassifyList',
        name: 'houseClassifyList',
        title: '房产列表',
        component: () => import('@/views/houseClassifyList/index.vue'),
        props: (route) => ({ classifyId: route.query.id, houseTitle: route.query.title })
      },
      // 房产经纪
      {
        path: 'agent',
        name: 'agent',
        title: '房产经纪',
        component: () => import('@/views/agent/index.vue'),
        props: (route) => ({ agentId: route.query.id, agentName: route.query.name })
      },
      // 关于我们页面
      {
        path: 'about',
        name: 'about',
        component: () => import('@/views/about/index.vue')
      },
      // 房产经纪
      {
        path: 'houseAgentList',
        name: 'houseAgentList',
        title: '房产列表',
        component: () => import('@/views/houseAgentList/index.vue')
      },
      {
        path: 'search',
        name: 'search',
        title: '房产搜索',
        component: () => import('@/views/search/index.vue')
      }
    ]
  },
  // 一级登录路由
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login/index.vue')
  },
  // 一级注册路由
  {
    path: '/register',
    name: 'register',
    component: () => import('@/views/register/index.vue')
  }
]

const router = new VueRouter({
  routes
})

export default router
